﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Backup.Services.Entities;
using BackupObjects.Taging;

namespace Backup.Services.Logic
{
    /// <summary>
    /// The implementation of tag service logic.
    /// </summary>
    public class TagServiceLogic:ITagServiceLogic
    {
        private readonly TagRepository _tagRepository=new TagRepository();

        public TagEntity Save(TagEntity tagEntity)
        {
            return _tagRepository.Save(tagEntity);
        }

        public void Delete(Guid id)
        {
            _tagRepository.Delete(id);
        }

        public TagEntity Load(Guid id)
        {
            return _tagRepository.Load(id);
        }

        public List<TagEntity> LoadAll()
        {
            return _tagRepository.LoadAll().ConvertAll<TagEntity>(item=>item);
        }

        public List<TagEntity> LoadAllByIds(List<Guid> ids)
        {
            if(ids==null)
            {
                return new List<TagEntity>();
            }

            return _tagRepository.Load(ids).ConvertAll<TagEntity>(item => item);
        }

        public List<TagEntity> GetChildrens(TagEntity tag)
        {
            return _tagRepository.GetChildrens(tag).ConvertAll<TagEntity>(item=>item);
        }

        public TagEntity GetParent(TagEntity tag)
        {
            return _tagRepository.GetParent(tag);
        }
    }
}
